package ro.gateway.aida.obj;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: GenericActivityProperty.java,v 1.1 2004/10/24 23:37:10 mihaipostelnicu Exp $
 */
public class GenericActivityProperty extends AIDAActivityObject
{
      private Hashtable names;

      public GenericActivityProperty()
      {
            this.names = new Hashtable();
            this.objectType = TYPE_GENERIC_UNKNOWN;
      }

	public GenericActivityProperty(String lang,String name)
		  {
			this.names = new Hashtable();
			names.put(lang,name);
		  }

      public GenericActivityProperty( byte object_type )
      {
            this.names = new Hashtable();
            this.objectType = object_type;
      }

      public void setName( String lang, String name )
      {
            if ( lang == null )
            {
                  return;
            }

            if ( name != null )
            {
                  this.names.put( lang, name );
            }
            else
            {
                  this.names.remove( lang );
            }
      }

      public String getName( String lang )
      {
            if ( lang == null )
            {
                  return null;
            }

            String result = ( String ) names.get( lang );
            if ( result == null )
            {
                  String lng = "ro";
                  if ( names.get( lng ) == null )
                  {
                        lng = "en";
                        if ( names.get( lng ) == null )
                        {
                              if ( names.size() > 0 )
                              {
                                    lng = ( String ) names.keys().nextElement();
                              }
                        }
                  }

                  String name = ( String ) names.get( lng );
                  if ( name != null )
                  {
                        result = name + " (" + lng + ")";
                  }
            }
//            if (result==null) return "Unamed item!";
            return result;
      }

      public void clearNames()
      {
            this.names.clear();
      }

      public String[] getAvailableLanguages()
      {
            if ( names.size() < 1 )
                  return null;

            String[] result = new String[ names.size() ];
            Enumeration en = names.keys();
            int i = 0;
            while ( en.hasMoreElements() )
            {
                  result[ i++ ] = ( String ) en.nextElement();
            }

            return result;
      }

      public boolean equals( AIDAComponent component )
      {
            if ( ( this.id == -1 ) && ( component.id == -1 ) )
            {
                  return false;
            }
            return this.id == component.getId();
      }

      /**
       * @deprecated
       * not used ???
       * @param table
       * @return
       */
      public static final GenericActivityProperty createFromHashtable(
            Hashtable table )
      {

            GenericActivityProperty result = new GenericActivityProperty();
            result.names = table;
            return result;

      }
	/**
	 * @return
	 */
	public Hashtable getNames() {
		return names;
	}

	/**
	 * @param hashtable
	 */
	public void setNames(Hashtable hashtable) {
		names = hashtable;
	}

}
